/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.score.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.fosung.frame.common.config.Global;
import com.fosung.frame.common.persistence.Page;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.modules.score.entity.PersonScoreDetail;
import com.fosung.frame.modules.score.service.PersonScoreDetailService;

/**
 * 党员积分内容明细Controller
 * @author ygl
 * @version 2017-09-03
 */
@Controller
@RequestMapping(value = "${adminPath}/score/personScoreDetail")
public class PersonScoreDetailController extends BaseController {

	@Autowired
	private PersonScoreDetailService personScoreDetailService;
	
	@ModelAttribute
	public PersonScoreDetail get(@RequestParam(required=false) String id) {
		PersonScoreDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = personScoreDetailService.get(id);
		}
		if (entity == null){
			entity = new PersonScoreDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("score:personScoreDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(PersonScoreDetail personScoreDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<PersonScoreDetail> page = personScoreDetailService.findPage(new Page<PersonScoreDetail>(request, response), personScoreDetail); 
		model.addAttribute("page", page);
		return "modules/score/personScoreDetailList";
	}

	@RequiresPermissions("score:personScoreDetail:view")
	@RequestMapping(value = "form")
	public String form(PersonScoreDetail personScoreDetail, Model model) {
		model.addAttribute("personScoreDetail", personScoreDetail);
		return "modules/score/personScoreDetailForm";
	}

	@RequiresPermissions("score:personScoreDetail:edit")
	@RequestMapping(value = "save")
	public String save(PersonScoreDetail personScoreDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, personScoreDetail)){
			return form(personScoreDetail, model);
		}
		personScoreDetailService.save(personScoreDetail);
		addMessage(redirectAttributes, "保存党员积分内容明细成功");
		return "redirect:"+Global.getAdminPath()+"/score/personScoreDetail/?repage";
	}
	
	@RequiresPermissions("score:personScoreDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(PersonScoreDetail personScoreDetail, RedirectAttributes redirectAttributes) {
		personScoreDetailService.delete(personScoreDetail);
		addMessage(redirectAttributes, "删除党员积分内容明细成功");
		return "redirect:"+Global.getAdminPath()+"/score/personScoreDetail/?repage";
	}

}